# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libtirpc' 'libtirpc-devel')
pkgver=0.2.5
pkgrel=1
pkgdesc="A port of Sun's Transport-Independent RPC library"
arch=('i686' 'x86_64')
license=('BSD')
url="https://libtirpc.sourceforge.io/"
makedepends=('gcc' 'make' 'patch' 'heimdal-devel')
source=(https://downloads.sourceforge.net/libtirpc/libtirpc-${pkgver}.tar.bz2
        0.2.4-cygwin-bindresvport.patch
        0.2.4-cygwin-ipv6.patch
        0.2.4-cygwin-no-nis.patch
        0.2.4-cygwin-poll.patch
        0.2.4-cygwin-pthread.patch
        0.2.4-cygwin-rpc-types.patch
        0.2.4-getrpcbynumber.patch
        0.2.4-no-undefined.patch
        msys2-autotools.patch)
sha256sums=('62f9de7c2c8686c568757730e1fef66502a0e00d6cacf33546d0267984e002db'
            '779e523ce028fa5015225c805bb66982e33f4395c14147a0e23726e4c6a3b8f1'
            '24d8f179812434e3be91800eb4387fec38d9050f3d1902ee1e66246c776fac11'
            'e030b86eccdc9bbbcde5f745af260afc8a872056fd2a5154dbe4b30e297685d0'
            '90cedf3f930bf44dbbed2e520305df1a53daddac464d1d68edf501466578ac0c'
            'd45ae803c401ca5a37e5084da822ff7f448241be38d457ef981692322e7fd057'
            'c247c94a431c0548610c6e97b620a3f81767a31f894b14027737b8afbade95f8'
            '0f6352d65c2708b51425af25702385a3da69955061b736b94955d028ef766c42'
            '67950f25c0451975e4554ecc04088bb2e2bfc895d2e48cb30fa5cd7ffef269b3'
            '4ab58d9b37794fa574f970b6b94eb1818d94f93a909ffd090ab6c83fd6ba4dae')

prepare() {
  cd libtirpc-${pkgver}
  patch -p2 -i $srcdir/0.2.4-cygwin-bindresvport.patch
  patch -p2 -i $srcdir/0.2.4-cygwin-ipv6.patch
  patch -p2 -i $srcdir/0.2.4-cygwin-no-nis.patch
  patch -p2 -i $srcdir/0.2.4-cygwin-poll.patch
  patch -p2 -i $srcdir/0.2.4-cygwin-pthread.patch
  patch -p2 -i $srcdir/0.2.4-cygwin-rpc-types.patch
  patch -p2 -i $srcdir/0.2.4-getrpcbynumber.patch
  patch -p2 -i $srcdir/0.2.4-no-undefined.patch
  patch -p1 -i $srcdir/msys2-autotools.patch

  autoreconf -i
}

build() {
  cd libtirpc-${pkgver}
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --enable-gssapi
  make
  make DESTDIR=$srcdir/dest install
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package_libtirpc() {
  depends=('msys2-runtime' 'gcc-libs')
  groups=('libraries')

  mkdir -p $pkgdir/usr/bin
  cp -f $srcdir/dest/usr/bin/*.dll $pkgdir/usr/bin/
  cp -rf $srcdir/dest/etc $pkgdir/
  cp -rf $srcdir/dest/usr/share $pkgdir/usr/
}

package_libtirpc-devel() {
  pkgdesc="Libtirpc headers and libraries"
  groups=('development')
  depends=("libtirpc=${pkgver}")

  mkdir -p $pkgdir/usr
  cp -rf $srcdir/dest/usr/include $pkgdir/usr/
  cp -rf $srcdir/dest/usr/lib $pkgdir/usr/
}
